const mongoose = require('mongoose')

mongoose.connect('mongodb://localhost/playground')
    .then(() => console.log('数据库连接成功'))
    .catch(err => console.log(err, '数据库连接失败'))

//  创建集合规则
const userSchema = new mongoose.Schema({
    name: String,
    age: Number,
    email: String,
    password: String,
    hobbies: [String]
})

// 使用规则创建集合
const User = mongoose.model('User', userSchema)

// User.findOneAndDelete({ _id: '5c09f294aeb04b22f8460969' }).then(result => console.log(result))

// 删除多条文档
User.deleteMany({}).then(result => console.log(result))